//
//  AGLChannelCollectionCell.m
//  滴滴快拍
//
//  Created by dllo on 16/5/19.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AGLChannelCollectionCell.h"
#import "AFNetworking.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@interface AGLChannelCollectionCell ()

@property (nonatomic, strong) BaseView *iconBackImage;

@end

@implementation AGLChannelCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
        
    }
    
    return self;
}

- (void)setChannel:(AGLChannel *)channel {
    if (_channel != channel) {
        _channel = channel;
    }
    [self createData];
}

- (void)createView {
    
    self.picImage = [[BaseImageView alloc] init];
    [self.contentView addSubview:self.picImage];
    
    self.iconImage = [[BaseImageView alloc] init];
    self.iconBackImage = [[BaseView alloc] init];
    [self.contentView addSubview:self.iconBackImage];
    [self.iconBackImage addSubview:self.iconImage];

    
    self.nickLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.nickLabel];

    
    self.ftLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.ftLabel];

    
    self.lcntLabel = [[BaseLabel alloc] init];
    [self.contentView addSubview:self.lcntLabel];

    self.likeImage = [[BaseImageView alloc] init];
    [self.contentView addSubview:self.likeImage];
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.picImage.frame = CGRectMake(0, 0, WIDTH, HEIGHT - 60);
    
    self.iconBackImage.frame = CGRectMake(10, (HEIGHT - 60) - 20, WIDTH / 5, WIDTH / 5);
    self.iconBackImage.layer.cornerRadius = WIDTH / 10;
    self.iconBackImage.layer.masksToBounds = YES;
    self.iconImage.frame = CGRectMake(5, 5, WIDTH/5-10, WIDTH/5-10);
    self.iconImage.layer.cornerRadius = (WIDTH/5-10)/2;
    self.iconImage.layer.masksToBounds = YES;
    
    self.nickLabel.frame = CGRectMake(WIDTH / 5 +10, HEIGHT - 60 + 5, WIDTH / 5*3-20, 12);
    self.nickLabel.font = [UIFont systemFontOfSize:12];
    self.nickLabel.textColor = [UIColor grayColor];
    
//    self.lcntLabel.frame = CGRectMake(WIDTH - 5 - 20, HEIGHT - 60 + 5, 20, 10);
    self.lcntLabel.frame = CGRectMake(WIDTH / 5 * 4, HEIGHT - 60 + 5, WIDTH / 5 - 5, 10);
    self.lcntLabel.font = [UIFont systemFontOfSize:10];
    self.lcntLabel.textColor = [UIColor grayColor];

    self.likeImage.frame = CGRectMake(WIDTH / 5 * 4-10,  HEIGHT - 60 + 5, 10, 10);
    self.likeImage.image = [UIImage imageNamed:@"heart"];
    
    self.ftLabel.frame = CGRectMake(10, (HEIGHT - 60) - 20 + WIDTH/5 + 10, WIDTH - 20, 20);
    self.ftLabel.font = [UIFont systemFontOfSize:15];
    

    
}

- (void)createData {
    NSString *picUrl = [NSString stringWithFormat:@"%@%@", self.channel.picbase, self.channel.picm];
    [self.picImage setImageWithURL:[NSURL URLWithString:picUrl]
                  placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
    
    [self.iconImage setImageWithURL:[NSURL URLWithString:self.channel.icon] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
    
    self.nickLabel.text = self.channel.nick;
    
    self.ftLabel.text = self.channel.ft;
    self.lcntLabel.text = [NSString stringWithFormat:@"%@", _channel.lcnt];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
